#ifndef rtps_SimpleHistoryCache_H
#define rtps_SimpleHistoryCache_H


#include "rtps/common/types.h"
#include "rtps/config.h"
#include "rtps/storages/CacheChange.h"
#include "rtps/storages/PBufWrapper.h"

#ifdef __cplusplus
extern "C" {
#endif

struct rtps_SimpleHistoryCache {
    struct rtps_CacheChange *m_buffer[HISTORY_SIZE + 1];
    uint16_t m_head;
    uint16_t m_tail;
    SequenceNumber_t m_lastUsedSequenceNumber;
};

struct rtps_SimpleHistoryCache *
rtps_SimpleHistoryCache_init(SequenceNumber_t lastUsed);

bool
rtps_SimpleHistoryCache_isFull(struct rtps_SimpleHistoryCache *shc);

SequenceNumber_t
rtps_SimpleHistoryCache_getSeqNumMin(struct rtps_SimpleHistoryCache *shc);

SequenceNumber_t
rtps_SimpleHistoryCache_getSeqNumMax(struct rtps_SimpleHistoryCache *shc);

struct rtps_CacheChange *
rtps_SimpleHistoryCache_addChange(struct rtps_SimpleHistoryCache *shc, const uint8_t *data, DataSize_t size);

void
rtps_SimpleHistoryCache_dropOldest(struct rtps_SimpleHistoryCache * shc);

void
rtps_SimpleHistoryCache_removeUntilIncl(struct rtps_SimpleHistoryCache *shc, SequenceNumber_t sn);

struct rtps_CacheChange *
rtps_SimpleHistoryCache_getChangeBySN(struct rtps_SimpleHistoryCache * shc, SequenceNumber_t sn);

#ifdef __cplusplus
}
#endif

#endif
